
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/12/2011 00:51:26
-- Generated from EDMX file: C:\Users\Sikilaxx01\Documents\Visual Studio 2010\Projects\ServerII\ServerII\AuthenticationLibrary\DataBaseModel\ServerIIDataBaseModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [RFADataBase];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ParentFeedChildFeed]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ChildFeeds] DROP CONSTRAINT [FK_ParentFeedChildFeed];
GO
IF OBJECT_ID(N'[dbo].[FK_ParentFeedUserVsParentFeed]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserVsParentFeeds] DROP CONSTRAINT [FK_ParentFeedUserVsParentFeed];
GO
IF OBJECT_ID(N'[dbo].[FK_UserUserVsParentFeed]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserVsParentFeeds] DROP CONSTRAINT [FK_UserUserVsParentFeed];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[ChildFeeds]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ChildFeeds];
GO
IF OBJECT_ID(N'[dbo].[ParentFeeds]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ParentFeeds];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[UserVsParentFeeds]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserVsParentFeeds];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ChildFeeds'
CREATE TABLE [dbo].[ChildFeeds] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Link] nvarchar(max)  NOT NULL,
    [Author] nvarchar(max)  NOT NULL,
    [Pubdate] nvarchar(max)  NOT NULL,
    [Lastupdatedate] nvarchar(max)  NOT NULL,
    [Category] nvarchar(max)  NOT NULL,
    [Summary] nvarchar(max)  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [ParentFeedId] int  NOT NULL,
    [Shared] bit  NOT NULL,
    [Owner] nvarchar(max)  NOT NULL,
    [Guest] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ParentFeeds'
CREATE TABLE [dbo].[ParentFeeds] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Link] nvarchar(max)  NOT NULL,
    [Lastupdatedate] nvarchar(max)  NOT NULL,
    [Author] nvarchar(max)  NOT NULL,
    [Category] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Question] nvarchar(max)  NOT NULL,
    [Answer] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UserVsParentFeeds'
CREATE TABLE [dbo].[UserVsParentFeeds] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [ParentFeedId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'ChildFeeds'
ALTER TABLE [dbo].[ChildFeeds]
ADD CONSTRAINT [PK_ChildFeeds]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ParentFeeds'
ALTER TABLE [dbo].[ParentFeeds]
ADD CONSTRAINT [PK_ParentFeeds]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserVsParentFeeds'
ALTER TABLE [dbo].[UserVsParentFeeds]
ADD CONSTRAINT [PK_UserVsParentFeeds]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ParentFeedId] in table 'ChildFeeds'
ALTER TABLE [dbo].[ChildFeeds]
ADD CONSTRAINT [FK_ParentFeedChildFeed]
    FOREIGN KEY ([ParentFeedId])
    REFERENCES [dbo].[ParentFeeds]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParentFeedChildFeed'
CREATE INDEX [IX_FK_ParentFeedChildFeed]
ON [dbo].[ChildFeeds]
    ([ParentFeedId]);
GO

-- Creating foreign key on [ParentFeedId] in table 'UserVsParentFeeds'
ALTER TABLE [dbo].[UserVsParentFeeds]
ADD CONSTRAINT [FK_ParentFeedUserVsParentFeed]
    FOREIGN KEY ([ParentFeedId])
    REFERENCES [dbo].[ParentFeeds]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParentFeedUserVsParentFeed'
CREATE INDEX [IX_FK_ParentFeedUserVsParentFeed]
ON [dbo].[UserVsParentFeeds]
    ([ParentFeedId]);
GO

-- Creating foreign key on [UserId] in table 'UserVsParentFeeds'
ALTER TABLE [dbo].[UserVsParentFeeds]
ADD CONSTRAINT [FK_UserUserVsParentFeed]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserUserVsParentFeed'
CREATE INDEX [IX_FK_UserUserVsParentFeed]
ON [dbo].[UserVsParentFeeds]
    ([UserId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------